﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;

namespace Winwise.SPWebConfig.Core
{
    public static class ExtensionWebService
    {
        public static void ApplyCustomWebConfigModifications(this SPWebService service)
        {
            WebConfigJobDefinition definition = new WebConfigJobDefinition(service)
            {
                Schedule = new SPOneTimeSchedule(DateTime.Now)
            };
            try
            {
                definition.Update();
                return;
            }
            catch (Exception exception)
            {
                if (exception is SPDuplicateObjectException)
                {
                    throw new InvalidOperationException(SPResource.GetString("WebconfigModificationAlreadyRunning", new object[0]), exception);
                }
                throw;
            }

        }
    }
}
